function qs(ele) {
    return document.querySelector(ele)
}
qs()

// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426
axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

async function fn(){
    const {data: {data}} = await axios("/city/province")
    console.log(data);
    const provStr = data.map(item => {
        const {name , province} = item
        return `
        <option value="${province}">${name}</option>
        `
    })
    qs("#province").innerHTML = '<option value="">请选择省份</option>' + provStr
}
fn()

qs("#province").addEventListener("change", async function(){
    console.log(this.value);

    const {data: {data}}= await axios("/city/city",{
        params: {
            provinceCode: this.value
        }
    }
    )
    const cityStr = data.map(item => {
        const {name, city } = item 
        return `
			<option value="${city}">${name}</option>
        `
    })
    qs("#city").innerHTML = '<option value="">请选择城市</option>' + cityStr
    qs("#county").innerHTML = '<option value="">请选择区县</option>'

})

qs("#city").addEventListener("change", async function(){
    const {data: {data}} = await axios("/city/area",{
        params: {
            provinceCode: qs("#province").value,
            cityCode: this.value
        }
    }
    )
    // console.log(data);

    const areaStr = data.map(item => {
        const {name, area} = item 
        return `
			<option value="${area}">${name}</option>
        `
    })
    qs("#county").innerHTML = '<option value="">请选择区县</option>' + areaStr

})
